/**
 * date: 2011-9-21
 * author : Eason
 * description : 以字节数组为加载成果的加载类.
 * 该类
 **/
package com.pickgliss.loader
{
	import com.pickgliss.ui.ComponentSetting;
	
	import flash.events.Event;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.utils.ByteArray;
	
	[Event(name="cancel",type="flash.events.Event")]
	public class ByteAimLoader extends BaseLoader
	{
		private var _bytes : ByteArray;
		public function ByteAimLoader(id:int, url:String, args:URLVariables=null, requestMethod:String=URLRequestMethod.GET)
		{
			super(id, url, args, requestMethod);
		}
		override public function loadFromBytes(data:ByteArray):void
		{
			if(data)data.position = 0;
			_bytes = data;
			fireCompleteEvent();
		}
		override protected function __onDataLoadComplete(event:Event):void
		{
			var md5:String = ComponentSetting.getUrlMd5(url);
			LoaderSavingManager.cacheFile(url,_loader.data,false,md5);
			super.__onDataLoadComplete(event)
		}
		override public function get content():*
		{
			if(_loader && _loader.data){
				return _loader.data;
			}
			return _bytes;
		}
		override public function dispose():void
		{
			dispatchEvent(new Event(Event.CANCEL));
			_bytes = null;
			super.dispose();
		}
	}
}